toDynamicFluidPx

fun Number.toDynamicFluidPx(context: Context, qualifier: DpQualifier, inverter: Inverter = Inverter.DEFAULT, ignoreMultiWindows: Boolean = false, applyAspectRatio: Boolean = false, customSensitivityK: Float? = null): Float

EN Converts a Number (base Dp value) into a dynamically scaled pixel Float for View-based (non-Compose) code.

The scaling logic:

  1. Builds a 64-bit packed cache key from all dimension parameters.

  2. If enableCache is true (default): checks DimenCache first. On a hit, returns the cached pixel value immediately. On a miss, calls calculateFluidDp and converts Dp→px via scaledDp * displayMetrics.density (equivalent to android.util.TypedValue.applyDimension for COMPLEX_UNIT_DIP), then stores the result.

  3. If enableCache is false: computes directly via calculateFluidDp, bypassing cache.

⚠️ Bypass note: when applyAspectRatio is false and qualifier is SMALL_WIDTH with DEFAULT inverter, the DimenCache.getOrPut call internally bypasses the hash lookup because a raw multiply (~2 ns) is faster than the cache access (~5 ns). Calls with these parameters measure raw math performance, NOT cache throughput.

Bulk resolution: for many keys in one pass, prefer building LongArray keys with DimenCache.buildKey and DimenCache.getBatch. Early init: call DimenSdp.warmupCache (or DimenSsp.warmupCache) once with your android.content.Context so persistence/DataStore work does not land on the first hot-frame call.

PT Converte um Number (valor Dp base) em um Float em pixels dinamicamente escalado para código View-based.

A lógica de escalonamento:

  1. Constrói uma chave de cache de 64 bits a partir de todos os parâmetros da dimensão.

  2. Se enableCache for true (padrão): consulta o DimenCache primeiro. No acerto, retorna o valor em pixels cacheado; no miss, calcula via calculateFluidDp e armazena.

  3. Se enableCache for false: calcula diretamente via calculateFluidDp.

Return

Dynamically scaled pixel value as Float.

Parameters

context

Android android.content.Context for configuration and density access.

inverter

Orientation-based dimension swap rule (default: Inverter.DEFAULT).

ignoreMultiWindows

If true, returns the base value in pixels unscaled when in split-screen.

applyAspectRatio

If true, applies the aspect-ratio multiplier.

customSensitivityK

Override for the AR sensitivity constant (null = library default).